////////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2008 Chris Colinsky
// All Rights Reserved
//
// version	0.4
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

import sugarcookie.validators.ValidationResult;
import sugarcookie.utils.RegExp;

class sugarcookie.validators.PhoneNumberValidator {
	public static var allowedFormatChars:String = "()- .+";
	
	public static function validate(value:Object):ValidationResult {
		//   Valid Formats
		//   only validates US phone numbers
		//   123 123 4567
		//   123-123-4567
		//   (123) 123 4567
		//   (123) 123-4567
		
		//   Regular Expression
		//   /^\(\d{3}\)[ -]\d{3}[ -]\d{4}$/
		
		if (RegExp.match(value,"/[^"+allowedFormatChars+"\\d]+/") return new ValidationResult("Phone number contains restricted characters",true);
		if (!RegExp.match(value,"/^\\(\\d{3}\\)[ -]\\d{3}[ -]\\d{4}$/")) return new ValidationResult("Phone number is not a valid format",true);
	}
}